#include "Main.h"

Cubit* cubit;

void init()
{
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glClearColor(0.0, 0.0, 0.0, 1.0);

	programID = LoadShaders("Shaders\\vshader.glsl", "Shaders\\fshader.glsl");

	cubit = new Cubit(vec3(0, 0, 0), vec3(0, 0, 0));
	cubit->SetPoint(0, 0, 0, 0);
	cubit->SetPoint(1, 1, 0, 0);
	cubit->SetPoint(2, 1, 1, 0);
	cubit->SetPoint(3, 0, 1, 0);
	cubit->SetPoint(4, 0, 0, 1);
	cubit->SetPoint(5, 1, 0, 1);
	cubit->SetPoint(6, 1, 1, 1);
	cubit->SetPoint(7, 0, 1, 1);

	cubit->SetFace(0, 0, 1, 2, 3, vec4(1.0, 1.0, 1.0, 1.0));
	cubit->SetFace(1, 1, 5, 6, 2, vec4(1.0, 0.0, 0.0, 1.0));
	cubit->SetFace(2, 2, 6, 7, 3, vec4(1.0, 1.0, 0.0, 1.0));
	cubit->SetFace(3, 3, 7, 4, 0, vec4(0.0, 1.0, 0.0, 1.0));
	cubit->SetFace(4, 4, 0, 1, 5, vec4(0.0, 0.0, 1.0, 1.0));
	cubit->SetFace(5, 5, 4, 7, 6, vec4(1.0, 0.5, 0.0, 1.0));

	cubit->Initialize();
}

void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	cubit->Render();
	
	glutSwapBuffers();
}

void idle()
{
	glutPostRedisplay();
}

void keyPressed(unsigned char key, int x, int y)
{

}

void specialPressed(int key, int x, int y)
{

}

void OpenGL(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA);
	glutInitWindowSize(512, 512);

	glutInitContextVersion( 3, 2 );
    glutInitContextProfile( GLUT_CORE_PROFILE );

	glutCreateWindow("A6 - Geometry Warz");

    glewExperimental = GL_TRUE;
    glewInit();

    init();

    glutDisplayFunc(display);
	glutKeyboardFunc(keyPressed);
	glutSpecialFunc(specialPressed);
	glutIdleFunc(idle);

	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
    glutMainLoop();

	delete cubit;
}

int main(int argc, char** argv)
{
	OpenGL(argc, argv);
	getchar();
	
	return 0;
}